import React, {
  createContext, useContext, useMemo,
} from 'react';
import { inject } from 'mobx-react';
import { DataSet } from 'choerodon-ui/pro';
import { injectIntl } from 'react-intl';
import formDataSet from './formdataset';

interface ContextProps {
  selected: any,
  FormDataSet: any,
  modal: any,
  refresh: any,
}

const Store = createContext({} as ContextProps);

export function useBatchEditStore() {
  return useContext(Store);
}

export const StoreProvider = injectIntl(inject('AppState')((props: any) => {
  const {
    children,
  } = props;

  const FormDataSet = useMemo(() => new DataSet(formDataSet()), []);

  const value = {
    ...props,
    FormDataSet,
  };
  return (
    <Store.Provider value={value}>
      {children}
    </Store.Provider>
  );
}));
